//
//  MyTeacherViewController.m
//  test1
//
//  Created by 衣尚品1 on 15/4/30.
//  Copyright (c) 2015年 衣尚品1. All rights reserved.
//

#import "MyTeacherViewController.h"
#import "TeacherCell.h"
#import "RCIM.h"
#import "RCChatViewController.h"
#import "TeacherDetailViewController.h"
#import "AppDelegate.h"

@interface MyTeacherViewController ()

@end

@implementation MyTeacherViewController{
    NSMutableArray *teacherPic;
    NSMutableArray *teacherName;
    NSMutableArray *subject;
    NSMutableArray *price;
    NSMutableArray *score;
    AppDelegate *delegate;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    teacherPic = [[NSMutableArray alloc] initWithObjects:@"teacher4.jpg",@"teacher5.jpg",@"teacher6.jpg", nil];
    teacherName = [[NSMutableArray alloc] initWithObjects:@"张冲",@"吴正利",@"陈国斌", nil];
    subject = [[NSMutableArray alloc] initWithObjects:@"化学",@"语文",@"数学", nil];
    price = [[NSMutableArray alloc] initWithObjects:@"200元/小时",@"200元/小时",@"250元/小时", nil];
    score = [[NSMutableArray alloc] initWithObjects:@"0.9",@"0.8",@"0.9", nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gotoTalk:) name:@"MessageButton" object:nil];
}


- (void)gotoTalk:(NSNotification *)sender{
    [RCIM connectWithToken:@"eCauf2imkY+0nl7yAMbB4niPfKr/+taTIwNODqO7o6pxtt8w/VcnOhd7aCh+x+wrqwiNFOJJfoO88hF53jTBGg==" completion:^(NSString *userId) {
        
        RCChatViewController *chatViewController = [[RCIM sharedRCIM] createPrivateChat:@"2" title:sender.object completion:^{
        }];
        
        [self.navigationController pushViewController:chatViewController animated:YES
         ];
        
        self.tabBarController.tabBar.hidden = YES;
        
    } error:^(RCConnectErrorCode status) {
        
    }];
}


- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return teacherName.count;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 106;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellIdentify = @"teacherCell";
    
    UINib *nib = [UINib nibWithNibName:@"TeacherCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:cellIdentify];
    
    TeacherCell *cell = [[TeacherCell alloc] init];
    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    
    cell.nameLabel.text = teacherName[indexPath.row];
    cell.subjectLabel.text = subject[indexPath.row];
    cell.priceLabel.text = price[indexPath.row];
    cell.picImage.image = [UIImage imageNamed:teacherPic[indexPath.row]];
    cell.score = score[indexPath.row];
    [cell SetUpStar];

    
    cell.matchLabel.hidden = YES;
    cell.dataLabel.hidden = YES;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    delegate.teacherDetailDic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:teacherName[indexPath.row],@"name",teacherPic[indexPath.row],@"pic", nil];
    
    TeacherDetailViewController *detailCon = [self.storyboard instantiateViewControllerWithIdentifier:@"teacherDetail"];
    [self.navigationController pushViewController:detailCon animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
